#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the version 3 of the GNU Lesser General Public License
#   as published by the Free Software Foundation.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU Lesser General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Copyright (c) NEC Deutschland GmbH, NEC HPC Europe


from aggmon.metric_container import MetricContainer


__all__ = [ "GangliaXMLMetricContainer" ]


class GangliaXMLMetricContainer(MetricContainer):
    def __init__( self ):
        MetricContainer.__init__( self )

    def eq( self, metric1, metric2 ):
        assert hasattr( metric2, "time" ), "time missing in Ganglia XML metric:\n" + repr( metric2 )
        assert hasattr( metric2, "value" ), "value missing in Ganglia XML metric:\n" + repr( metric2 )
        assert hasattr( metric2, "tmax" ), "tmax missing in Ganglia XML metric:\n" + repr( metric2 )

        #print repr( metric1 ), "\n", repr( metric2 )

        if metric2.time < metric1.time + metric1.tmax and metric2.value == metric1.value:
            return True
        else:
            return False
